home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kolekce / d3456 / gmprintsuite_eval.exe / {app} / GmTreeViewPrint.pas < prev    next >
Pascal/Delphi Source File  |  2002-01-02  |  6KB  |  165 lines

  1. {******************************************************************************}
  2. {                                                                              }
  3. {                          TGmTreeViewPrint 2.3                                }
  4. {                                                                              }
  5. {           Copyright (c) 2001 Graham Murt  - www.MurtSoft.com                 }
  6. {                                                                              }
  7. {   Feel free to e-mail me with any comments, suggestions, bugs or help at:    }
  8. {                                                                              }
  9. {                           graham@murtsoft.com                                }
  10. {                                                                              }
  11. {******************************************************************************}
  12.  
  13. unit GmTreeViewPrint;
  14.  
  15. interface
  16.  
  17. uses
  18.   Windows, Messages, SysUtils, Classes, ComCtrls, Forms, GmPreview;
  19.  
  20. type
  21.   TGmTreeViewPrint = class(TComponent)
  22.   private
  23.     FExpandNodes: Boolean;
  24.     FIndent: TGmValue;
  25.     FItemHeight: TGmValue;
  26.     FPreview: TGmPreview;
  27.     { Private declarations }
  28.   protected
  29.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  30.     { Protected declarations }
  31.   public
  32.     constructor Create(AOwner: TComponent); override;
  33.     destructor Destroy; override;
  34.     procedure TreeViewToPage(X, Y: integer; AUnits: TGmMeasurement; ATreeView: TTreeView);
  35.     property Indent: TGmValue read FIndent write FIndent;
  36.     property ItemHeight: TGmValue read FItemHeight write FItemHeight;
  37.     { Public declarations }
  38.   published
  39.     property ExpandNodes: Boolean read FExpandNodes write FExpandNodes default True;
  40.     property Preview: TGmPreview read FPreview write FPreview;
  41.     { Published declarations }
  42.   end;
  43.  
  44. implementation
  45.  
  46. uses Graphics, GmConst;
  47.  
  48. constructor TGmTreeViewPrint.Create(AOwner: TComponent);
  49. begin
  50.   inherited Create(AOwner);
  51.   FExpandNodes := True;
  52.   FIndent := TGmValue.Create;
  53.   FIndent.AsUnits := 600;
  54.   FItemHeight := TGmValue.Create;
  55.   FItemHeight.AsUnits := 600;
  56. end;
  57.  
  58. destructor TGmTreeViewPrint.Destroy;
  59. begin
  60.   FIndent.Free;
  61.   FItemHeight.Free;
  62.   inherited Destroy;
  63. end;
  64.  
  65. procedure TGmTreeViewPrint.Notification(AComponent: TComponent; Operation: TOperation);
  66. begin
  67.   inherited Notification(AComponent, Operation);
  68.   if (Operation = opRemove) and (AComponent = FPreview) then
  69.     FPreview := nil;
  70. end;
  71.  
  72. procedure TGmTreeViewPrint.TreeViewToPage(X, Y: integer; AUnits: TGmMeasurement; ATreeView: TTreeView);
  73. var
  74.   TreeView: TTreeView;
  75.   AForm: TForm;
  76.   ICount: integer;
  77.   StartX,
  78.   CurrentY: integer;
  79.   StartY,
  80.   CurrentX: integer;
  81.   Image: TBitmap;
  82.   AIndent: integer;
  83.   ImageHeight: integer;
  84.   ImageWidth: integer;
  85.   LevelChanged: Boolean;
  86.   LastLevel: integer;
  87.   //CurrentNode: integer;
  88.   IsVisible: Boolean;
  89. begin
  90.   LastLevel := 0;
  91.   if Assigned(FPreview) then
  92.   begin
  93.     TreeView := TTreeView.Create(nil);
  94.     AForm := TForm.Create(nil);
  95.     TreeView.Parent := AForm;
  96.     Image := TBitmap.Create;
  97.     try
  98.       TreeView.Items.Assign(ATreeView.Items);
  99.       TreeView.Images := ATreeView.Images;
  100.       if FExpandNodes then TreeView.FullExpand;
  101.       StartX := Round(ConvertValue(X, AUnits, GmUnits));
  102.       StartY := Round(ConvertValue(Y, AUnits, GmUnits));
  103.  
  104.       CurrentY := StartY;
  105.  
  106.       for ICount := 0 to TreeView.Items.Count-1 do
  107.       begin
  108.         if FExpandNodes then IsVisible := True else
  109.           IsVisible := ATreeView.Items[ICount].IsVisible;
  110.         if (IsVisible) then
  111.         with FPreview.Canvas do
  112.         begin
  113.           Pen.Color := clSilver;
  114.           //Pen.Style := psDot;
  115.           AIndent := Indent.AsUnits;
  116.           LevelChanged := LastLevel <> TreeView.Items[ICount].Level+1;
  117.           LastLevel := TreeView.Items[ICount].Level+1;
  118.           CurrentX := StartX + (AIndent * (LastLevel));
  119.           //CurrentY := StartY + (FItemHeight.AsUnits * (CurrentNode));
  120.           Image.Canvas.FillRect(Rect(0,0,Image.Width, Image.Height));
  121.           TreeView.Images.GetBitmap(TreeView.Items[ICount].ImageIndex, Image);
  122.           ImageHeight := Round((Image.Height * 2540) / Screen.PixelsPerInch);
  123.           ImageWidth  := Round((Image.Width * 2540) / Screen.PixelsPerInch);
  124.  
  125.           Line(StartX, CurrentY, StartX, CurrentY+FItemHeight.AsUnits, GmUnits);
  126.           MoveTo(CurrentX - (ImageWidth div 2) - 50,
  127.                  CurrentY ,//+ (ImageHeight div 2),
  128.                  GmUnits);
  129.           LineTo(CurrentX -(Indent.AsUnits),
  130.                  CurrentY ,//+ (ImageHeight div 2),
  131.                  GmUnits);
  132.           if LevelChanged then
  133.             LineTo(CurrentX -(Indent.AsUnits),
  134.                    CurrentY - (FItemHeight.AsUnits-(ImageHeight div 2))+50,
  135.                    GmUnits)
  136.           else
  137.             LineTo(CurrentX -(Indent.AsUnits),
  138.                    CurrentY - (FItemHeight.AsUnits),
  139.                    GmUnits);
  140.  
  141.           Draw(CurrentX - (ImageWidth div 2), CurrentY - (ImageHeight div 2), Image, 1, GmUnits);
  142.           TextOut(CurrentX + ImageWidth, CurrentY-(ImageHeight div 2), TreeView.Items[ICount].Text, GmUnits);
  143.           if CurrentY > (FPreview.PageHeight.AsUnits - (FPreview.Margins.Bottom.AsUnits + +FPreview.Header.Height.AsUnits + 1000)) then
  144.           begin
  145.             CurrentY := StartY;
  146.             FPreview.NewPage;
  147.           end
  148.           else
  149.           Inc(CurrentY, FItemHeight.AsUnits);
  150.         end;
  151.         //FPreview.Canvas.Line(3000, CurrentY, 6000, CurrentY, GmUnits);
  152.       end;
  153.  
  154.     finally
  155.       TreeView.Free;
  156.       AForm.Free;
  157.       Image.Free;
  158.       FPreview.UpdatePreview;
  159.     end;
  160.   end;
  161. end;
  162.  
  163.  
  164. end.
  165.